package tests;

import junit.framework.TestCase;
import objects.User;
import DB.DataBase;

public class DBTest extends TestCase {
	DataBase d=new DataBase();
	
	public void testDB() {
		assertTrue(d!=null);
		assertTrue(d.getUsers().size()==1); //manager
	}

	public void testAddForum() {
		d.addForum("Asaf");
		assertEquals(d.getForums().get(0).getForumName(), "Asaf");
		
	}

	public void testAddThreadToFroum() {
		d.addThreadToFroum("Asaf", "Manassen");
		assertEquals(d.getThreads(d.findFroum("Asaf")).get(0).getThreadName(), "Manassen");
	}


	public void testAddUser()
	{
		User u=new User();
		u.setUserName("Asaf");
		System.err.println(d.getUsers());
		d.addUser(u);
		System.err.println(d.getUsers());
		assertEquals(d.getUsers().size(),2);
		
	}

	public void testRemoveUser()
	{
		User u=new User();
		u.setUserName("Asaf2");
		System.err.println(d.getUsers());
		d.addUser(u);
		System.err.println(d.getUsers());
		d.removeUser(u);
		System.err.println(d.getUsers());
		assertEquals(d.getUsers().size(),2 );//manager + asaf
	}

	public void testAddMessage()
	{
		d.addMessage(d.getThreads("Asaf").get(0), "title",d.findUser("Asaf"), "msg");
	}

	public void testfindOwnerOfMessage()
	{
		assertEquals(d.findOwnerOfMessage("Asaf","Manassen", "title").getUserName(),"Asaf");
	}
	
	public void testremoveMessage()
	{
		d.removeMessageFromThread(d.findFroum("Asaf"), "Manassen", "title");
		assertEquals(d.getMessage(d.getThread(d.findFroum("Asaf"), "Manassen"), "title"),null);
	}
	
}
